<?php
header("Cache-control: private");
$this -> load -> view("header2");

$na = 0;
$ioc = '';


if(!empty($post_data["importance"]))
$importance = $post_data["importance"];

if (!empty($post_data["importance"])) {
	$ims = explode(",", $importance);
	
	foreach ($importance_of_customers as $name => $value) {
		

		foreach($ims as $key => $ims_value){
			//echo $ims_value. '=='. $value->value.'<br>';
			if(trim($ims_value) == trim($value->value)){
				$ioc .= $value -> importance_of_customers_id.',';
			}
			
		}
		
	}	
}

//echo $ioc;

if (!empty($post_data["nationality"]))
	foreach ($nationality as $_n => $_v) {

		if (false !== ($rst = strpos($post_data["nationality"], $_v -> value))) {
			$na .= "," . $_v -> nationality_id;
		}
	}

//print_r($post_data);

?>

<span style="display:none;" id="all_show" >
	<font color="red">全頁選取</font>
</span>
<input type="hidden"  id="all_page" value="1" >

<input type="hidden"  id="name" value="<?= !empty($post_data["name"]) ? $post_data["name"] : ''; ?>" >
<input type="hidden"  id="recommended" value="<?= !empty($post_data["recommended"]) ? $post_data["recommended"] : ''; ?>" >
<input type="hidden"  id="importance" value="<?= !empty($post_data["importance"]) ? $post_data["importance"] : ''; ?>" >
<input type="hidden"  id="nationality" value="<?= !empty($na) ? $na : ''; ?>" >

<input type="hidden"  id="home_address" value="<?= !empty($post_data["home_address"]) ? $post_data["home_address"] : ''; ?>" >
<input type="hidden"  id="building_name" value="<?= !empty($post_data["building_name"]) ? $post_data["building_name"] : ''; ?>" >
<input type="hidden"  id="mobile" value="<?= !empty($post_data["mobile"]) ? $post_data["mobile"] : ''; ?>" >
<input type="hidden"  id="customer_source" value="<?= !empty($post_data["customer_source"]) ? $post_data["customer_source"] : ''; ?>" >

<input type="hidden"  id="category" value="<?= !empty($post_data["category"]) ? $post_data["category"] : ''; ?>" >
<input type="hidden"  id="company_name" value="<?= !empty($post_data["company_name"]) ? $post_data["company_name"] : ''; ?>" >

<input type="hidden"  id="sctime"       value="<?= !empty($post_data["sctime"]) ? $post_data["sctime"] : ''; ?>" >
<input type="hidden"  id="ectime"       value="<?= !empty($post_data["ectime"]) ? $post_data["ectime"] : ''; ?>" >
<input type="hidden"  id="sbirthday"    value="<?= !empty($post_data["sbirthday"]) ? $post_data["sbirthday"] : ''; ?>" >
<input type="hidden"  id="ebirthday"    value="<?= !empty($post_data["ebirthday"]) ? $post_data["ebirthday"] : ''; ?>" >

<input type="hidden"  id="send_publication" value="<?= !empty($post_data["send_publication"]) ? $post_data["send_publication"] : ''; ?>" >
<input type="hidden"  id="send_email" value="<?= !empty($post_data["send_email"]) ? $post_data["send_email"] : ''; ?>" >
<input type="hidden"  id="gifts" value="<?= !empty($post_data["gifts"]) ? $post_data["gifts"] : ''; ?>" >

<input type="hidden"  id="broker" value="<?= !empty($post_data["broker"]) ? $post_data["broker"] : ''; ?>" >
<input type="hidden"  id="keywords" value="<?= !empty($post_data["keywords"]) ? $post_data["keywords"] : ''; ?>" >

<div id="content">

	<link rel="stylesheet" href="<?= base_url() ?>css/crid_style.css" />
	<link rel="stylesheet" type="text/css" href="<?= base_url() ?>css/flexigrid.pack.css" />
	<script type="text/javascript" src="<?= base_url() ?>js/flexigrid.pack.js"></script>
	<script type="text/javascript" src="<?= base_url() ?>js/flexigrid2.js"></script>
	
	<div >
		<div id="search_page" style="<?=empty($_POST)?"display:none;":""?>">
			<?=$search_page;?>
		</div>

		<div style="margin: 0px 0px 0px 52px" >	
			<table class="flexme4" style="display: none"></table>
		</div >
	</div>
	
	
	<script type="text/javascript">

				$(".flexme4").flexigrid({
		url: '/client/client_sf_josn',
		dataType: 'json',
		colModel: [
		
		{
		display: '姓名',
		name: 'name',
		width: 100,
		sortable: true,
		align: 'left'
		},
		{
		display: '手機',
		name: 'mobile',
		width: 100,
		sortable: true,
		align: 'left'
		},
		{
		display: '住家電話',
		name: 'home_phone',
		width: 100,
		sortable: true,
		align: 'left'//,
		//hide : true
		}
		,
		{
		display: 'E-mail',
		name: 'email',
		width: 100,
		sortable: true,
		align: 'left'
		}
		,
		{
		display: '地址',
		name: 'home_address',
		width: 240,
		sortable: true,
		align: 'left'
		}		
		,
		{
			display: '公司名稱',
			name: 'company_name',
			width: 100,
			sortable: true,
			align: 'left'
		}

		,
		{
			display: '公司電話',
			name: 'company_phone',
			width: 100,
			sortable: true,
			align: 'left'
		}
		, 
		{
		display: '特徴',
		name: 'recommended',
		width: 100,
		sortable: true,
		align: 'left'
		}, 
		 {
		display: '傳真',
		name: 'fax',
		width: 80,
		sortable: true,
		align: 'left'
		}
		, {
		display: '重要性',
		name: 'importance',
		width: 60,
		sortable: true,
		align: 'left'
		},
		{
		display: '公司地址',
		name: 'company_address',
		width: 240,
		sortable: true,
		align: 'left'
		},
		{
		display: '經紀人',
		name: 'broker',
		width: 40,
		sortable: true,
		align: 'left'
		},
		{
			display: '序號',
			name: 'client_id',
			width: 30,
			sortable: true,
			align: 'center'
		}
		],
		buttons: [
		<?php
if (check_menu_permissios("client_data_edit")) {
		?>
					{
		name: '編輯',
		bclass: 'edit',
		onpress: Example4
		}
		,
		<?php } ?>
					{
		name: 'Excel',
		bclass: 'coffee',
		onpress: Example4
		}
		,
		<?php
if (check_menu_permissios("client_data_delete")) {
		?>
					{
		name: '删除',
		bclass: 'delete',
		onpress: Example4
		}
		,
		<?php } ?>
		{
		name: 'edm',
		bclass: 'edm',
		onpress: Example4
		}
		,
		{
			name: '簡訊',
			bclass: 'sms',
			onpress: Example4
		}
		,
		{
			name: '全頁選取',
			bclass: 'sms',
			onpress: Example4
		}
		,
		{
			name: '進階條件',
			bclass: 'sms',
			onpress: Example4
		}
		,
		{
		separator: true
		}
		],
		nohresize: true,
		sortname: "mtime",
		sortorder: "desc",
		usepager: true,
		title: '客戶資料查詢结果',
		useRp: true,
		checkbox: true, // 是否要多選框
		rp: 10,
		width: '105%',
		height: 'auto',
		procmsg: '資料讀取中，請稍後…',
		nomsg: '找不到符合絛件的資料',
		//margin: 10px 1px 1px -53px
		});

		function Example4(com, grid) {

		if (com == '删除') {

			var empty_str = '';
			var _fg = true;
			$(".trSelected").each(function() {
	
				//var str = $(this).children().next().html();
				var str = $(this).children().next().next().next().next().next().next().next().next().next().next().next().next().next().html();
				//alert(str2);
				var str2 = str.split('</div>');
				var str = str2[0].split('>');
		
				if (_fg) {
		
				_fg = false;
				empty_str += parseInt(str[1]);
		
				} else {
		
				empty_str += "," + parseInt(str[1]);
		
				}
			});
	
			$.post('/client/save_client_id', {
			id: empty_str,
			is_del: '0'
	
			}, function(data) {
				$.post('/client/delete_client',
					function(data) {
					//alert(data);
						$(".flexme4").flexReload();
					});
				});

		}
		else if (com == '全頁選取') {

			var _flag = $("#all_page").val();

			//alert(_flag);
			if(_flag=='1'){
				$("#all_show").show();
				$("#all_page").val('2');
			}else {
				$("#all_show").hide();
				$("#all_page").val('1');
			}
			//alert(_flag);
	}else if (com == '進階條件') {

			$("#search_page").toggle();
	}else if (com == '編輯') {

		$(".trSelected").each(function() {
		var str = $(this).children().next().next().next().next().next().next().next().next().next().next().next().next().next().html();
		var str2 = str.split('</div>');
		var str = str2[0].split('>');
		//group +=str+',';
		var url = '/client/data_edit?id=' + parseInt(str[1]);

		document.location.href = url;

		});

	}else if (com == '簡訊') {
		var group='';

		$(".trSelected").each(function() {

		var str = $(this).children().next().next().next().next().next().next().next().next().next().next().next().next().next().html();
		var str2 = str.split('</div>');
		var str = str2[0].split('>');
		//var url = '/send_sms/index?id=' + parseInt(str[1]);
		group = group +str[1] +',';
		//document.location.href = url;

		});
		var url = '/send_sms/index?id=' + group;

		document.location.href = url;

		//alert(group);

		}
		else if (com == 'edm') {

		var group_id = '';

		$(".trSelected").each(function() {

		var str = $(this).children().next().next().next().next().next().next().next().next().next().next().next().next().next().html();
		var str2 = str.split('</div>');
		var str = str2[0].split('>');
		//var url = '/send_edm/index?id=' + parseInt(str[1]);
		//document.location.href = url;
		group_id += str[1] + ',';
		});

		var url = '/send_edm/index?id=' + group_id;
		document.location.href = url;

		//alert(group_id);

	}else if (com == 'Excel') { 

				var empty_str = '';
				var _fg = true;
				var _flag = $("#all_page").val();

				if(parseInt(_flag)==2){
					//全部的client	
					//alert('allllwww');
					//excel_all_client
					$.post('/client/save_client_id', {

						id: empty_str,
						is_del: '0'

					}, function(data) {

						//var url = '/client/excel_all_client';
						var url = '/js/blog/public/getClientExcelAll';
						document.location.href = url;

					});

				}else{

					$(".trSelected").each(function() {

						var str = $(this).children().next().next().next().next().next().next().next().next().next().next().next().next().next().html();
						//var str = $(this).children().next().html();
						var str2 = str.split('</div>');
						var str = str2[0].split('>');

						if (_fg) {

						_fg = false;
						empty_str += parseInt(str[1]);

						} else {

						empty_str += "," + parseInt(str[1]);

						}
					});

					//$.post('/client/save_client_id', {

					$.post('/js/blog/public/postClientId', {	

						id: empty_str,
						is_del: '0'

					}, function(data) {
						//alert(data);
						var url = '/js/blog/public/getClientExcelById';
						document.location.href = url;

					});
			}		
		}

		}

		function save_client(id) {

		$.get('/client/get_save_client_id', {
		id: id
		}, function(data) {

		});

		}

		function query() {

		var home_address = $("#home_address").val();
		var building_name = $("#building_name").val();

		var mobile = $("#mobile").val();
		var customer_source = $("#customer_source").val();
		var category = $("#category").val();
		var company_name = $("#company_name").val();

		var sctime = $("#sctime").val();
		var ectime = $("#ectime").val();
		var sbirthday = $("#sbirthday").val();
		var ebirthday = $("#ebirthday").val();

		var send_publication = $("#send_publication").val();
		var send_email = $("#send_email").val();
		var gifts = $("#gifts").val();

		var keywords = $("#keywords").val();
		var name = $("#name").val();
		var broker = $("#broker").val();
		var recommended = $("#recommended").val();
		var importance = $("#importance").val();
		var nationality = $("#nationality").val();

		//alert(importance);

		$(".flexme4").flexOptions(
		{newp: 1, params:
		[

		{name: 'mobile',
		value: mobile}
		,
		{name: 'customer_source',
		value: customer_source}
		,
		{name: 'category',
		value: category}
		,
		{name: 'company_name',
		value: company_name}
		,

		{name: 'home_address',
		value: home_address}
		,
		{name: 'building_name',
		value: building_name}
		,

		{name: 'ectime',
		value: ectime}
		,
		{name: 'sctime',
		value: sctime}
		,

		{name: 'gifts',
		value: gifts}
		,
		{name: 'sbirthday',
		value: sbirthday}
		,
		{name: 'ebirthday',
		value: ebirthday}
		,
		{name: 'send_publication',
		value: send_publication}
		,
		{name: 'send_email',
		value: send_email}
		,
		{name: 'name',
		value: name}
		,
		{name: 'keywords',
		value: keywords}
		,
		{name: 'broker',
		value: broker}
		,
		{name: 'recommended',
		value: recommended}
		,
		{name: 'importance',
		value: importance}
		,
		{name: 'nationality',
		value: nationality}
		]
		}).flexReload();
		}

		$("document").ready(function() {

		setTimeout('query()', 600);

		});
	</script>
</div>
<?=
isset($footer) ? $footer : ''
?>